<template>
	<view class="active">
		<view class="title" style="text-align: center;">
			<span style="font-size: 24px;">京东登录</span>
		</view>

		<view>
			<form @submit="formSubmit">
				<view class="uni-form-item uni-column account">
					<input class="uni-input" name="account" placeholder="请输入账号" />
				</view>
				<view class="uni-form-item uni-column password">
					<input class="uni-input" name="password" type="password" placeholder="请输入密码" />
				</view>
				<view class="uni-btn-v uni-submit">
					<button form-type="submit">登录</button>
				</view>
				<view class="uni-btn-v">
					<button @click="navRegis()">注册</button>
				</view>
			</form>
		</view>
	</view>
</template>

<script>
	import {
		isLogin
	} from '../../apiRequest/login';
	export default {
		data() {
			return {}
		},
		methods: {
			formSubmit: function(e) {
				let formdata = e.detail.value;
				isLogin(formdata.account, formdata.password).then(login => {
					if (login.token != null && login.token != '') {
						uni.showToast({
							title: "登录成功",
							duration: 2000
						});
						uni.setStorageSync("token", login.token);
						this.$login();
						if (uni.setStorageSync("argsUrl") != '' && uni.setStorageSync("argsUrl") != null) {
							uni.navigateTo({
								url: uni.getStorageSync("argsUrl")
							})
						} else {
							uni.reLaunch({
								url: '/pages/index/index',
								duration:2000
							})
						}
					} else {
						uni.setStorageSync("token", '');
						uni.showToast({
							title: "账号或密码错误",
							duration: 2000
						});
					}
				})
			},
			navRegis(){
				uni.redirectTo({
					url:'/pages/login/register'
				})
			}
		}
	}
</script>

<style>
	.account {
		margin-top: 30px;
		margin-left: 20px;
		margin-right: 20px;
		border-bottom: 1px solid black;
	}

	.password {
		margin-top: 30px;
		margin-left: 20px;
		margin-right: 20px;
		border-bottom: 1px solid black;
	}

	.uni-submit {
		margin-top: 30px;
		margin-left: 20px;
		margin-right: 20px;
	}
</style>